package com.rytx.framework.web.service;

import com.rytx.common.core.domain.model.ArtUser;
import com.rytx.common.core.domain.model.LoginUser;
import com.rytx.common.utils.StringUtils;
import com.rytx.system.mapper.ArtUserMapper;
import com.rytx.system.service.IArtUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

@Component("ArtUserDetailsServiceImpl")
public class ArtUserDetailsServiceImpl implements UserDetailsService {
    private static final Logger log = LoggerFactory.getLogger(ArtUserDetailsServiceImpl.class);


    @Autowired
    private IArtUserService artUserService;

    @Override
    public UserDetails loadUserByUsername(String phone) throws UsernameNotFoundException {
        ArtUser artUser = artUserService.selectArtUserByPhone(phone);
        if(StringUtils.isNull(artUser)){
            log.info("登录用户：{} 不存在.", phone);
            throw new UsernameNotFoundException("登录用户：" + phone + " 不存在");
        }
        return new LoginUser(artUser.getId(),artUser);
    }
}
